PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

With Timeout Statements

When AppleScript sends a command to an application, it normally waits for the command to complete execution before continuing with the rest of the script. If the command takes longer than one minute to complete, AppleScript stops running the script and returns the error "event timed out" . AppleScript does not cancel the operation--it merely stops execution of the script.

A With Timeout statement lets you change how long AppleScript waits before stopping execution of a script. The amount of time you specify in a With Timeout statement applies to some types of commands within the statement that are sent to other applications, but not to any commands sent to the application that's running the script.

As with AppleScript's default timeout of one minute, when a With Timeout statement times out, AppleScript does not cancel the operation--it merely stops execution of the script. In addition, AppleScript can only check for a timeout if the application that gets the command yields time to the script. If an application is nonresponsive (clicking on the screen produces no result), the timeout may not be checked. For example, the following statement will not time out if the user fails to dismiss the modal Save dialog:

with timeout of 5 seconds
    tell application "AppleWorks"
        close front document saving ask
    end tell
end timeout

Your script can use a With Timeout statement in conjunction with a Try statement so that it has the opportunity to deal with a timeout. However, whether your script can send a command to cancel the offending lengthy operation after a timeout is dependent on the application that is performing the command.

The time specified by a With Timeout statement applies to all application commands and to any scripting addition commands whose targets are application objects, which includes scripting addition commands whose direct parameters are application objects and scripting addition commands within Tell statements to application objects. The time specified by a With Timeout statement does not apply to AppleScript commands, AppleScript operations, or scripting addition commands whose targets are not application objects.

Note

If you want AppleScript to proceed to the next statement without waiting for application commands to complete, use an Ignoring statement to ignore the application responses attribute. For more information, see Considering and Ignoring Statements.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)